<?php 
use lib\email_template;
use lib\XFDB;
define('Copyright_content', '该系统由绪飞网络工作室 版权所有
请勿二开或破解谢谢配合
请勿删除此文件');

function rethreffun($msg){//返回跳转函数
    return "window.location.href='".$msg."';";
}




function sysmsg($msg,$send=false){
        $title='站点提示信息';
        if($send)exitjson(-1,$msg);
    	exit("<!DOCTYPE html>\n    <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"zh-CN\">\n    <head>\n        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n        <title>".$title."</title>\n        <style type=\"text/css\">\nhtml{background:#eee}body{background:#fff;color:#333;font-family:\"微软雅黑\",\"Microsoft YaHei\",sans-serif;margin:2em auto;padding:1em 2em;max-width:700px;-webkit-box-shadow:10px 10px 10px rgba(0,0,0,.13);box-shadow:10px 10px 10px rgba(0,0,0,.13);opacity:.8}h1{border-bottom:1px solid #dadada;clear:both;color:#666;font:24px \"微软雅黑\",\"Microsoft YaHei\",,sans-serif;margin:30px 0 0 0;padding:0;padding-bottom:7px}#error-page{margin-top:50px}h3{text-align:center}#error-page p{font-size:9px;line-height:1.5;margin:25px 0 20px}#error-page code{font-family:Consolas,Monaco,monospace}ul li{margin-bottom:10px;font-size:9px}a{color:#21759B;text-decoration:none;margin-top:-10px}a:hover{color:#D54E21}.button{background:#f7f7f7;border:1px solid #ccc;color:#555;display:inline-block;text-decoration:none;font-size:9px;line-height:26px;height:28px;margin:0;padding:0 10px 1px;cursor:pointer;-webkit-border-radius:3px;-webkit-appearance:none;border-radius:3px;white-space:nowrap;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-box-shadow:inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);box-shadow:inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);vertical-align:top}.button.button-large{height:29px;line-height:28px;padding:0 12px}.button:focus,.button:hover{background:#fafafa;border-color:#999;color:#222}.button:focus{-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2)}.button:active{background:#eee;border-color:#999;color:#333;-webkit-box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5);box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5)}table{table-layout:auto;border:1px solid #333;empty-cells:show;border-collapse:collapse}th{padding:4px;border:1px solid #333;overflow:hidden;color:#333;background:#eee}td{padding:4px;border:1px solid #333;overflow:hidden;color:#333}\n        </style>\n    </head>\n    <body id=\"error-page\">\n        <h3>".$title."</h3>\n        ".$msg."\n    </body>\n    </html>");
}
function Copyright_tips(){
    exit(
        '<h2>检测到版权文件已删除</h2>如果版权文件被删除我们将不会在运行本程序<br>稍后系统会为你自动生成版权文件 请手动刷新<br>为了尊重原版请勿再删除</b></font><br/>'
        );
}
//返回弹窗 并带跳转url
function alerttc($msg=null,$url="index_min",$url1 = './?s='){
    if($msg){
        exit("<script language='javascript'>alert('".$msg."');window.location.href='".$url1.$url."';</script>");
    }else{
        exit("<script language='javascript'>window.location.href='".$url1.$url."';</script>");  
    }
}
//返回 弹窗
function minalerttc($msg){
    global $httphost;
     exit("<script language='javascript'>alert('".$msg."');window.location.href='".$httphost."/User';</script>");  
}

//layui 弹窗
function layuialert($msg,$url=null){
    if(empty($url)){
          exit("<script language='javascript'>layer.alert('".$msg."', function() { window.location.href='./'; });</script>");
    }else{
       exit("<script language='javascript'>layer.alert('".$msg."', function() { window.location.href='".$url."'; });</script>"); 
    }
    
}

function cookie_zt($zt, $type = NULL, $addtime = NULL, $endtime = NULL, $wx_name = NULL, $i = NULL, $crontime = NULL,$cookie=NULL,$xf_stat=NULL,$xf_type=NULL)
{
    global $DB, $conf, $date;
    
    if($i == '1'){
        return cookie_zt_pc($zt,$crontime,$type);
    }
    
    if($type == 'wxpay'){
        if ($zt != '1') {
                if ($i == '0') {
                    return '<font color=red>微信未绑定店员或店员掉线->' . $endtime . '</font>';
                } else if ($i == '2') {
                    if ($xf_type == '1' || $xf_type == '7' || $xf_type == '8' || $xf_type == '9' || $xf_type == '10') {
                        return '<font color=red>微信MAC云端不在线或已掉线</font>';
                    } else {
                        return '<font color=red>微信UOS云端不在线或已掉线</font>';
                    }
                }
            } else if ($zt == '1') {
                if ($i == '0') {
                    $login_time = time();
                    $login_wxpay = $DB->query('SELECT * FROM `pay_wechat_trumpet` WHERE `status`=\'1\' and `login_time`>\'' . $login_time . '\' and `wx_name`=\'' . $wx_name . '\' limit 1')->fetch();
                    if ($login_wxpay !== false) {
                        return '<font color=green>微信已成功绑定,店员已登录</font>';
                    } else {
                        return '<font color=red>微信绑定的店员已掉线,请联系站长处理</font>';
                    }
                } else if ($i == '2') {
                    if ($xf_type == '1' || $xf_type == '7' || $xf_type == '8' || $xf_type == '9' || $xf_type == '10') {
                        return '<font color=green>微信MAC云端状态正常</font>';
                    } else {
                        return '<font color=green>微信UOS云端状态正常</font>';
                    }
                }
            }
    }else if($type == 'alipay'){
        return $zt == '1' ? '<font color=green>' . ($cookie == 'xfqydmfxy' ? '支付宝当面付' : ($cookie == 'xfqymckxy' ? '支付宝免CK' : '支付宝云端')) . '状态正常</font>' : '<font color=red>支付宝云端不在线或已掉线</font>';
    }else if($type == 'qqpay'){
        return $xf_stat == '1' ? qqpayzt($zt,$xf_type) : '<font color=' . ($zt == '1' ? 'green' : 'red') . '>QQ云端' . ($zt == '1' ? '状态正常' : '不在线或已掉线') . '</font>';
    }else if($type == 'usdtpay'){
        return '<font color=' . ($zt == '1' ? 'green' : 'red') . '>USDT收款' . ($zt == '1' ? '状态正常' : '异常') . '</font>'; 
    }else if($type == 'wxpayqq'){
        return '<font color=' . ($zt == '1' ? 'green' : 'red') . '>微信转QQH5按钮' . ($zt == '1' ? '正常' : '掉线') . '</font>'; 
    }
}

function cookie_zt_pc($zt,$crontime,$type=null)
{
    return '<font color=' . ($zt == 1 && $crontime > time() ? 'green' : 'red') . '>' . ($type == 'wxpay' ? '微信' : ($type == 'qqpay' ? 'QQ' : ($type == 'alipay' ? '支付宝' : 'PC软件'))) . ($zt == 1 && $crontime > time() ? '挂机软件正常在线' : '挂机软件不在线或已掉线') . '</font>';
}

function qqpayzt($zt,$xf_type){
    $xf_type = ($xf_type == 4)?3:$xf_type;
    $statusText = $zt == '1' ? '状态正常' : '不在线或已掉线';
    return '<font color=' . ($zt == '1' ? 'green' : 'red') . '>QQ' . ($xf_type == '3' ? '手表协议' : ($xf_type == '2' || $xf_type == '1' ? 'PC协议' : ($xf_type == '5' ? 'Linux协议' : ''))) . $statusText . '</font>';
}
function wachat_login_zt($login_time)//微信店员在线状态
{
	if($login_time>=time())
		return '<font color=green>在线</font>';
	else
		return '<font color=red>不在线</font>';
}
//循环拼接邮箱模板 并配合Mailbox_sending_template使用
function generateParagraphs($data, $defaultFontSize = null) {
    $paragraphs = '';
    foreach ($data as $item) {
        $label = $item['label'];
        $value = $item['value'];
        $fontSize = isset($item['fontSize']) ? $item['fontSize'] : $defaultFontSize;
        $style = "margin-left:40px;";
        if ($fontSize) {
            $style .= " font-size:{$fontSize}px;";
        }

        $paragraphs .= "<p style=\"$style\">$label$value</p>";
    }

    return $paragraphs;
}

//拼接 邮箱模板 
function Mailbox_sending_template($data,$title) {
     global $conf,$httphost;
    $msg = '<div style="border-style:solid; border-width:1px; border-color:#2baee9; width:640px;padding:10px;" >
                <img src="'.$httphost.'/Core/assets/img/logo.png"  height="50" width="150">
                <p align="center" style="font-size:26px;">'.$title.'-'.$conf['sitename'].'</p>
                <hr style="border:1 dashed #987cb9" color="#987cb9" size="1">
                <p style="margin-left:50px;">尊敬的'.$data['user'].'您好!</p>'
                . generateParagraphs($data['paragraphs']) .
            '</div>';
    return $msg;
}
function submit_head1(){
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html>
        <head>
        	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        	<title>正在为您跳转到支付页面，请稍候...</title>
            ';
}

function submit_head(){
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html>
        <head>
        	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        	<title>正在为您跳转到支付页面，请稍候...</title>
            <style type="text/css">
                body {margin:0;padding:0;}
                p {position:absolute;
                    left:50%;top:50%;
                    width:500px;height:50px;
                    margin:-60px 0 0 -260px;
                    padding:50px;font:bold 28px/60px "宋体", Arial;
                    background:#f9fafc url(Core/Assets/Lmg/load.gif) no-repeat 20px 26px;
                    text-indent:22px;border:1px solid #c5d0dc;}
                #waiting {font-family:Arial;}
            </style>';
}

function userimgadaption($url = 'login') {
    // 设置默认的背景图片 URL
    $defaultImageUrl = isMobile() ? 'https://api.oick.cn/random/api.php?type=pe' : 'https://aapi.93bk.cn/api.php?key=1ysap0ij6e6ucaA5x1c9kno93au11r20g7xdea';

    // 根据 URL 类型选择不同的样式和背景图片
    $containerClass = ($url == 'login') ? 'container-login100' : 'row lyear-wrapper';
    $backgroundImage = "background-image: url($defaultImageUrl); background-size: cover;";

    // 输出 HTML 代码
    echo "<div class=\"$containerClass\" style=\"$backgroundImage\">";
}

function email_authti(){
    echo '<div class="alert alert-danger"><span class="btn-sm btn-danger">重要</span>&nbsp;请完成邮箱认证，否则您的账号无法正常使用！ <a href="./?s=emailauth" class="btn btn-default btn-xs">立即验证</a></div>';
}
function fetchTimelineItems() {
    // 执行 SQL 查询
    $rs = safeSqlQuery("SELECT * FROM pay_notice WHERE status='1' ORDER BY id ASC LIMIT 5", [], 'select');
    // 生成 HTML 内容
    $timelineItems = '';
    foreach ($rs['result'] as $res) {
        $timelineItems .= '
            <div class="timeline-item">
                <div class="timeline-item-info">
                    <i class="iconfont icon-tixing" style="font-size: 20px;color: '.($res['color'] ? $res['color'] : '').'"></i>
                    <a href="#">'.$res['title'].'</a></i>
                    <small><font color="'.($res['color'] ? $res['color'] : '').'">'.$res['datatxt'].'</font></small>
                    <p class="mb-0 pb-2">
                        <small style="color:#66CCFF;">'.$res['addtime'].'</small>
                    </p>
                </div>
            </div>';
    }
    return $timelineItems;
}
//循环拼接
function Loop_splicing_form($data){
     $paragraphs = '';
     foreach ($data as $item) {
          $label = $item['label'];
          $value = $item['value'];
          $style = $item['style'];
          if(!empty($style)){
              $paragraphs .= "<td style='".$style."'>$label</td>"; 
          }else{
              if (empty($value)) {
                   $paragraphs .= "<td><b>$label</b></td>";  
              } else {
                   $paragraphs .= "<td><b style='".$style."'>$label</b><br><b style='".$style."'>$value</b></td>";  
              }
          }
          
     }
     return $paragraphs;
}
//拼接表格
function Splicing_form($data){
    $html = '
    <tr>
    '.Loop_splicing_form($data).'
    </tr>
    ';
    return $html;
}
function pay_type($type) {
    $types = [
        'qqpay' => 'QQ钱包',
        'alipay' => '支付宝',
        'wxpay' => '微信',
        'usdtpay' => 'USDT',
        'wxpayqq' => '微信转QQ',
        'all' => '统计'
    ];

    return isset($types[$type]) ? '<font color="green">' . $types[$type] . '</font>' : '';
}

function order_zt($status) {
    $statuses = [
        1 => '<font color="green">已完成</font>',
        2 => '<font color="red">订单失效</font>'
    ];

    return isset($statuses[$status]) ? $statuses[$status] : '<font color="red">未完成</font>';
}
function pay_passtemplate(){
    global $userrow;
    if(empty($_SESSION['pay_pass']) || $_SESSION['pay_pass'] !== $userrow['pay_pass']){
        $html = '<div class="container-fluid p-t-15">
            <div class="row">
                <div class="col-md-12 col-lg-12 col-xl-6">
                    <div class="card bg-white m-b-30">
                        <div class="card-body new-user">
                            <h4 class="header-title mb-4 mt-0">请先验证二级密码</h4>
                                <div class="panel-body">
                                    <div class="form-group">
                                        <label>本页面需要验证二级密码才可访问，初次使用随便填</label>
                                        <input type="password" id="pay_pass" name="pay_pass" placeholder="请输入您绑定的二级密码" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <button type="button" class="btn btn-block btn-primary" onclick="pay_pass();">确定</button>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
     </div>';
     exit($html);
    }
}
function table_page($page,$pages,$min_url){
          $linka = '';
         $linka.= '</tbody></table></div>';
         $linka.= '<div class="text-center"><ul class="pagination">';
        $first=1;
        $prev=$page-1;
        $next=$page+1;
        $last=$pages;
        $link='';
        if(isset($_GET['my'])&&$_GET['my']=='search'&&isset($_GET['column'])&&isset($_GET['value'])){
        $link.="&my=search&column=".$_GET['column']."&value=".$_GET['value'];
        }
        
        if($page>1){
         $linka.= '<li class="page-item"><a class="page-link" href="?s='.$min_url.'&page='.$first.$link.'">首页</a></li>';
        $linka.= '<li class="page-item"><a class="page-link" href="?s='.$min_url.'&page='.$prev.$link.'">上一页</a></li>';
        }
        
        $start = 1;
        if ($page >= 10) {
            $start = $page - 9;
        }
        $end = min($pages, $start + 19);
        for ($i = $start; $i <= $end; $i++) {
            if ($page == $i) {
                $linka.='<li class="paginate_button page-item active"><a class="page-link">'.$i.'</a></li>';
            } else {
                $linka.= '<li class="paginate_button page-item"><a class="page-link" href="?s='.$min_url.'&page='.$i.$link.'">'.$i.'</a></li>';
            }
        }
        if($page<$pages){
        $linka.= '<li class="page-item"><a class="page-link" href="?s='.$min_url.'&page='.$next.$link.'">下一页</a></li>';
        $linka.= '<li class="page-item"><a class="page-link" href="?s='.$min_url.'&page='.$last.$link.'">末页</a></li>';
        }
       $linka.= '</ul></div>';
       echo $linka;
}
function generateTableRowWithFunction($row, $res) {
    $hookType = ($row !== false) ? (($row['hook_type'] == 1 || $row['hook_type'] == 3) ? '<font color=#0000FF>挂机版</font>' : '<font color=green>免挂机版</font>') : '<font color="red">该二维码已删除</font>';
    $beizhu = $row && $row['beizhu'] ? $row['beizhu'] : '无备注';
    return ' ['. $hookType .']->'. $res['qr_id'] .'→'. $beizhu;
}
function getStatusLabel($status) {
    switch ($status) {
        case '2':
            return '<font style="color: #808080;">待审核</font>';
        case '1':
            return '<font style="color: #00FF00;">已通过</font>';
        case '0':
            return '<font style="color: #FF0000;">已拒绝</font>';
        default:
            return '';
    }
}
function generateQRListItem($res) {
    $type = $res['type'];
    $beizhu = $res['beizhu'];
    $money = $res['money'];
    $id = $res['id'];
    $cookie = $res['cookie'];

    $icon = '<img src="/Core/assets/icon/' . $type . '.ico" width="16" onerror="this.style.display=\'none\'">';
    $typeText = pay_type($type);
    $beizhuText = '备注: [' . $beizhu . ']';

    $balanceText = ($res['hook_type']  == 0 && $res['type'] != 'wxpay' &&  ($res['cookie'] != 'xfqymckxy' && $res['cookie'] != 'xfqydmfxy'))?$money :'不支持此功能';

    $detailLink = '<a href="javascript:;" onclick="showQrlist(\''.$res['id'].'\');" title="点击查看详情">查看详细</a>';

    return $icon . $typeText . '<br/>' . $beizhuText . '<br/>' . $balanceText . '</br>' . $detailLink;
}
function generateQRStatusItem($res) {
    $status = $res['status'];
    $type = $res['type'];
    $addtime = $res['addtime'];
    $endtime = $res['endtime'];
    $wx_name = $res['wx_name'];
    $hook_type = $res['hook_type'];
    $crontime = $res['crontime'];
    $cookie = $res['cookie'];
    $xf_stat = $res['xf_stat'];
    $xf_type = $res['xf_type'];
    $cookieStatus = cookie_zt($status, $type, $addtime, $endtime, $wx_name, $hook_type, $crontime, $cookie, $xf_stat, $xf_type);
    $addtimeText = $res['addtime'];

    $currentTime = (($res['type']=='alipay' && ($res['cookie'] == 'xfqymckxy' || $res['cookie'] == 'xfqydmfxy')) || ($res['type'] == 'wxpay' && $res['hook_type']!=2 && $res['status'] == '1') ) ? date('Y-m-d H:i:s', time()) : date('Y-m-d H:i:s', $res['crontime']);
    $updateButton = '';

    if ($res['type'] == 'qqpay' && $res['xf_stat'] == '1') {
        $updateButton = '<a href="#Up_QQPC_Qr_modal" onclick="GET_QQBUDX(\'' . $res['id'] . '\');" class="btn btn-xs btn-success"><i class="fa fa-arrow-circle-o-up"></i> 更新</a>';
    } elseif ($res['type'] == 'wxpay' && $res['hook_type'] == '2') {
        $updateButton = '<a href="#Up_Qr_modal" onclick="Get_Wxyun(\'' . $res['id'] . '\');" class="btn btn-xs btn-success"><i class="fa fa-arrow-circle-o-up"></i> 更新</a>';
    } else {
        $updateButton = '<a href="#Up_Qr_modal" onclick="Get_Qr(\'' . $res['id'] . '\');" class="btn btn-xs btn-success"><i class="fa fa-arrow-circle-o-up"></i> 更新</a>';
    }

    $deleteButton = '<a onclick="Del_Qr(\'' . $res['id'] . '\');" class="btn btn-xs btn-danger"><i class="mdi mdi-trash-o"></i>删除</a>';
    $editButton = '<a onclick="editSave(\'' . $res['id'] . '\');" class="btn btn-xs btn-success"><i class="mdi mdi-pencil"></i></a>';

    return $cookieStatus . '<br/>' . $addtimeText . '<br/>' . $currentTime . '</br>' . $updateButton . '&nbsp;' . $deleteButton . '&nbsp;' . $editButton;
}

function generateTableCell($res) {
    $status   = $res['status'];
    $crontime = $res['crontime'];
    $type     = $res['type'];
    $addtime  = $res['addtime'];
    $id       = $res['id'];
    $status_html = cookie_zt_pc($status, $crontime, $type);
    $addtime_html = date('Y-m-d H:i:s', $crontime);
    
    $edit_btn = '<a onclick="editSave(\'' . $id . '\');" class="btn btn-xs btn-success"><i class="mdi mdi-pencil"></i> 编辑</a>';
    $delete_btn = '<a onclick="Del_Qr(\''.$id.'\');" class="btn btn-xs btn-danger"><i class="mdi mdi-trash-o"></i>删除</a>';

    return $status_html.'<br/>'.$addtime.'<br/>'.$addtime_html.'<br/>'.$edit_btn.'&nbsp;'.$delete_btn.'&nbsp;';
}

function checkVipStatus($type) {
    global $userrow,$date;
    switch ($type) {
        case 'alipay':
            if ($userrow['alipay_free_vip_time'] > $date) {
                return '会员：' . $userrow['alipay_free_vip_time'];
            } else {
                return '非会员无法添加二维码';
            }
            break;
        case 'qqpay':
            if ($userrow['qqpay_free_vip_time'] > $date) {
                return '会员：' . $userrow['qqpay_free_vip_time'];
            } else {
                return '非会员无法添加二维码';
            }
            break;
        case 'wxpay':
            if ($userrow['wxpay_free_vip_time'] > $date) {
                return '会员：' . $userrow['wxpay_free_vip_time'];
            } else {
                return '非会员无法添加二维码';
            }
            break;
        default:
            return '未知支付类型';
    }
}

function displaynoneuser($option = '',$macurl = '',$uosurl = ''){
    $html = '
             <div id="type_alipay" style="display: none;">
                     <div class="form-group">
                         <label>支付宝挂机协议:</label><br>
                         <select class="form-control" name="alipay" id="alipay">
                             <option value="">请选择挂机方式</option>
                             <option value="1">云端协议一（平均10-15天 异地未知）</option>
                             <option value="2">本地协议二（平均15-30  异地未知）</option>
                             <option value="3">本地协议三（平均 10-30 异地未知）</option>
                             <option value="4">免CK协议(不掉线)</option>
                             <option value="5">当面付通道(不掉线)</option>
                        </select>
                     </div>
                </div>
                <div id="type_alipaymck" style="display: none;">
                       <div class="form-group">
                              <label>支付宝UID：</label>
                                <input type="text" class="form-control" id="alipaymck_uid">
                        </div>
                        <div class="form-group">
                              <label>支付宝APPID：</label>
                              <input type="text" class="form-control" id="alipaymck_appid">
                        </div>
                        <div class="form-group">
                          <label>支付宝公钥：</label>
                          <textarea class="form-control" rows="6" id= "alipaypublicmck_key"></textarea>
                        </div>
                        <div class="form-group">
                            <label>应用私钥：</label>
                            <textarea class="form-control" rows="6" id= "appprivatemck_key"></textarea>
                        </div>
                        <b>需签约《账单数据查询及账单下载服务》</b>
                </div>
                <div id="type_alipaydmf" style="display: none;">
                    <div class="form-group">
                          <label>支付宝APPID：</label>
                          <input type="text" class="form-control" id="alipaydmf_appid">
                    </div>
                    <div class="form-group">
                          <label>支付宝公钥：</label>
                          <textarea class="form-control" rows="6" id= "alipaypublicdmf_key"></textarea>
                    </div>
                    <div class="form-group">
                        <label>应用私钥：</label>
                        <textarea class="form-control" rows="6" id= "appprivatedmf_key"></textarea>
                    </div>
                    <b>需签约《当面付服务》</b>
                 </div>
                 <div id="type_qqpay" style="display: none;">
                     <div class="form-group">
                         <label>QQ挂机协议:</label><br>
                         <select class="form-control" name="qqpay" id="qqpay">
                             <option value="">请选择协议</option>
                             <option value="1">云端协议（两天左右掉线）</option>
                             <option value="">----------以下协议不掉线(勿选此项)---------</option>
                             <option value="2">QQPC协议</option>
                             <option value="3">QQ手表协议一</option>
                             <option value="4">QQ手表协议二</option>
                             <option value="5">LinuxQQ协议</option>
                          </select>  
                        </div> 
                  </div> 
                 <div id="type_wxpay" style="display: none;">
                    <div class="form-group">
                        <label>微信挂机协议:</label><br>
                        <select class="form-control" name="wxpay" id="wxpay">
                            <option value="">请选择协议</option>
                            <option value="1">微信店员</option>
                            <option value="2">Mac云端</option>
                            <option value="3">UOS云端</option>
                         </select> 
                    </div> 
                 </div> 
                 <div id="type_wxpaymac" style="display: none;">
                     <div class="form-group">
                         <label>请选择挂机类型(IMac):</label><br>
                         <select class="form-control" name="mactype" id="mactype">
                             <option value="">请选择要添加的通道</option>
                             <option value="1">个码免输通道</option>
                             <option value="7">个人收款单免输通道</option>
                             <option value="8">微信赞赏码通道(不免输)</option>
                             <option value="9">经营码通道(不免输)</option>
                             <option value="10">小微商家通道(不免输)</option>
                         </select>
                      </div>
                      <div class="form-group">
                        <label>请选择云端地址(MAC):</label><br> 
                            <select class="form-control" name="macwxyunurl" id="macwxyunurl">
                               <option value="">请选择云端地址(选择这个则使用默认云端)</option>
                               '.$macurl.'
                             </select>
                      </div>
                 </div>    
                 <div id="type_wxpayWindows" style="display: none;">
                     <div class="form-group">
                        <label>请选择挂机类型(UOS):</label><br> 
                            <select class="form-control" name="Windowstype" id="Windowstype">
                               <option value="">请选择要添加的通道</option>
                               <option value="3">个码通道(不免输)</option>
                               <option value="4">微信赞赏码通道(不免输)</option>
                               <option value="5">经营码通道(不免输)</option>
                               <option value="6">小微商家通道(不免输)</option>
                             </select>
                      </div>
                      <div class="form-group">
                        <label>请选择云端地址(UOS):</label><br> 
                            <select class="form-control" name="uoswxyunurl" id="uoswxyunurl">
                               <option value="">请选择云端地址(选择这个则使用默认云端)</option>
                               '.$uosurl.'
                             </select>
                      </div>
                 </div>
                 <div id="type_wxpaysc" style="display: none;">
                     <div class="form-group">
                         <label for="imgfile">选择二维码(剪切好边框再上传哦):</label><span class="glyphicon glyphicon-qrcode"></span>
                         <input type="file" class="form-control-file" id="imgfile" accept="image/*" multiple>
                     </div>
                </div>
                <div id="type_wxpayurl" style="display: none;">
                    <div class="form-group">
                        <label for="qr_url">二维码地址:</label><br>
                        <input type="text" class="form-control" id="qr_url" value="" placeholder="上传二维码自动识别,可修改" name="qr_url">
                    </div>
                </div>
                <div id="type_wxpaydy" style="display: none;">
                    <div class="form-group">
                        <label>请选择你要绑定微信店员:</label>
                         <select class="form-control" id="wx_name" name="wx_name" default="">
                             '.$option.'
                         </select>
                     </div>
                 </div>
                 
                 ';
        return $html;
}

function xfqrnostatusemail($email,$E_type=NULL){
    global $conf,$httphost;
    $sub = $conf['sitename'] . ' - COOKIE失效提醒';
    $msg = '尊敬的：' . $conf['sitename'] . '用户,您好! 您在' . $conf['sitename'] . '上挂的[' . $E_type . ']COOKIE失效了,为了不影响您继续使用,请务必去更新,地址:' . $httphost;
    $email= send_mail($email, $sub, $msg);
    return $email;
}

function xfhtemail($xf_pid=NULL,$xf_money=NULL,$E_type=NULL,$name=NULL,$trade_no=NULL){
    global $conf,$date,$httphost;
    $sub=$conf['sitename'].'- 收款到账提醒';
    $userrow = XFDB::userrow($xf_pid,'pid');
    $data=[
        'user'=>$userrow['user'],
        'paragraphs' => [
            ['label' => 'PID', 'value' => $xf_pid],
            ['label' => '订单号', 'value' => $trade_no],
            ['label' => '收款方式','value'=>$E_type],
            ['label' => '商品名称','value'=>$name],
            ['label' => '支付金额','value'=>$xf_money],
            ['label' => '站点地址','value'=>$httphost],
            ['label' => '有问题请联系站长QQ','value'=>$conf['qq']]
            ]
        ];
        $temp = order_emailtemp;
        $email= send_mail($userrow['email'], $conf['sitename'].'- 收款到账提醒', email_template::$temp($data,'新订单通知'));
        return $email;
        
}

function generateAlipayInfo($row) {
    // 初始化结果字符串
    $app = '';

    // 判断 cookie 是否为 'xfqymckxy'，如果是则生成支付宝UID输入框
    if ($row['cookie'] == 'xfqymckxy') {
        $app .= '<div class="form-group">
                     <label>支付宝UID：</label><br>
                     <input class="form-control" type="text" value="'.$row['alipayUId'].'" readonly="readonly"><br>
                 </div>';
    }

    // 生成支付宝APPID输入框
    $app .= '<div class="form-group">
                 <label>支付宝APPID：</label><br>
                 <input class="form-control" type="text" value="'.$row['alipayAppId'].'" readonly="readonly"><br>
             </div>';

    // 生成支付宝公钥文本框
    $app .= '<div class="form-group">
                 <label class="col-sm-2 control-label">支付宝公钥：</label><br>
                 <textarea class="form-control" rows="6" readonly="readonly">'.$row['alipayPublicKey'].'</textarea>
             </div>';

    // 生成应用私钥文本框
    $app .= '<div class="form-group">
                 <label>应用私钥：</label><br>
                 <textarea class="form-control" rows="6" readonly="readonly">'.$row['appPrivateKey'].'</textarea>
             </div>';

    // 返回生成的 HTML 代码
    return $app;
}
function generatePaymentRow($paymentMethod, $vipTime, $date) {
    
    $statusColor = $vipTime > $date ? 'blue' : 'red';
    $statusText = $vipTime > $date ? '开启' : '关闭';
    $expireColor = $vipTime > $date ? 'green' : 'red';
    $expireText = $vipTime > $date ? '到期：' . $vipTime : '未开通或已到期';

    $buttonText = $vipTime > $date ? '续期' : '开通';
    $buttonColor = $vipTime > $date ? 'success' : 'success';
    $name = array(
        'wxpay'=>'微信',
        'qqpay'=>'QQ',
        'alipay'=>'支付宝'
    );
    $onClick = "Pay_Buy('$paymentMethod')";

    $html = '<tr>';
    $html .= '<td>' . $name[$paymentMethod] . '</td>';
    $html .= '<td><a style="color: ' . $statusColor . ';">' . $statusText . '</a></td>';
    $html .= '<td><a href="#overview" class="btn btn-' . $buttonColor . ' mb-2 mr-2" onclick="' . $onClick . '">' . $buttonText . '</a><a style="color: ' . $expireColor . ';">' . $expireText . '</a></td>';
    $html .= '</tr>';

    return $html;
}

function Package_template($result = null) {
    $html = '';

    if (!$result) {
        $html = '
            <div class="col-sm-6">
                <div class="card text-center">
                    <div class="card-header bg-primary text-center">
                        <h4 class="m-0 ">暂无套餐</h4>
                    </div>
                    <div class="card-body">
                        <table class="table table-centered mb-0">
                            <thead>
                                <tr>
                                    <th class="text-center">时长：<strong>0</strong> 天</th>
                                </tr>
                                <tr>
                                    <th class="text-center">额度：<strong>0</strong> 元</th>
                                </tr>
                                <tr>
                                    <th class="text-center">价格：<strong>0</strong> 元</th>
                                </tr>
                                <tr>
                                    <th class="text-center">介绍：无</th>
                                </tr>
                            </thead>
                        </table>
                        <button class="btn btn-primary btn-round waves-effect waves-light mt-2" type="button">禁止购买</button>
                    </div>
                </div>
            </div>
        ';
    } else {
        foreach ($result as $res) {
            $introduce = (!empty($res['introduce']))?$res['introduce']:'无';
            $html .= '
                <div class="col-sm-6">
                    <div class="card text-center">
                        <div class="card-header bg-primary text-center">
                            <h4 class="m-0 ">' . $res['name'] . '</h4>
                        </div>
                        <div class="card-body">
                            <table class="table table-centered mb-0">
                                <thead>
                                    <tr>
                                        <th class="text-center">三网会员时长：<strong>' . $res['days'] . '</strong> 天</th>
                                    </tr>
                                    <tr>
                                        <th class="text-center">支付额度：<strong>' . $res['quota'] . '</strong> 元</th>
                                    </tr>
                                    <tr>
                                        <th class="text-center">购买价格：<strong>' . $res['price'] . '</strong> 元</th>
                                    </tr>
                                    <tr>
                                        <th class="text-center">套餐介绍：' . $introduce . '</th>
                                    </tr>
                                </thead>
                            </table>
                            <button class="btn btn-primary btn-round waves-effect waves-light mt-2" type="button" onclick="Pack_Buy(\'' . $res['id'] . '\');">立即购买</button>
                        </div>
                    </div>
                </div>
            ';
        }
    }
    return $html;
}

function userpay_set_template(){
        $itemsPerPage = 2; // 每页显示的数量
        $page = isset(input("get")['page']) ? (int)input("get")['page'] : 1; // 当前的页码
        $offset = ($page - 1) * $itemsPerPage; // 计算偏移量
        
        // 获取模板列表和记录总数
        $mblist = \lib\PayTemplate::getList(); // 这里你需要获取所有记录或符合某个条件的记录
        $totalTemplates = count($mblist);
        
        // 计算总页数
        $totalPages = ceil($totalTemplates / $itemsPerPage);
        
        // 获取当前页显示的记录
        $pageItems = array_slice($mblist, $offset, $itemsPerPage);
    $htmlParts = [];
    foreach ($pageItems as $pay_template) {
        $encodedTemplate = htmlspecialchars($pay_template, ENT_QUOTES, 'UTF-8');
        $templateHtml = <<<HTML
        <div class="col-xs-6 mblist" >
            <div class="card">
                <a href="javascript:;" onclick="Change_pay_Template('$encodedTemplate');">
                    <img class="card-img-top" src="/Submit/Template/{$encodedTemplate}/preview.png" onerror="this.onerror=null; this.src='/Submit/Template/{$encodedTemplate}/preview.png'" title="点击更换到该模板" style="height:300px;width:400px; object-fit: cover;">
                </a>
                <div class="card-body">
                    <p class="card-text">{$encodedTemplate}</p>
                </div>
            </div>
        </div>
HTML;
        $htmlParts[] = $templateHtml;
    }
    $html = implode("\n", $htmlParts);
    $linka = '<br><div class="text-center"><ul class="pagination">';
    $first = 1;
        $prev = $page - 1;
        $next = $page + 1;
        $last = $totalPages; // 假定$pages已被设置为总页数$totalPages
        
        $link = '';
        if($page > 1){
            $linka.= '<li class="page-item"><a class="page-link" href="?s=Pay_Set&page='.$first.$link.'">首页</a></li>';
            $linka.= '<li class="page-item"><a class="page-link" href="?s=Pay_Set&page='.$prev.$link.'">上一页</a></li>';
        }
        
        $start = max($first, $page - 5);
        $end = min($last, $page + 5);
        
        for ($i = $start; $i <= $end; $i++) {
            if ($page == $i) {
                $linka.='<li class="paginate_button page-item active"><a class="page-link">'.$i.'</a></li>';
            } else {
                $linka.= '<li class="paginate_button page-item"><a class="page-link" href="?s=Pay_Set&page='.$i.$link.'">'.$i.'</a></li>';
            }
        }
        
        if($page < $last){
            $linka.= '<li class="page-item"><a class="page-link" href="?s=Pay_Set&page='.$next.$link.'">下一页</a></li>';
            $linka.= '<li class="page-item"><a class="page-link" href="?s=Pay_Set&page='.$last.$link.'">末页</a></li>';
        }
        
        $linka .= '</ul></div>';
        $html .= $linka; // 将分页导航追加到主内容的HTML
        return $html;
    
}




?>